package cn.bqjr.platform.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bqjr.platform.model.entity.Order;
import cn.bqjr.platform.model.entity.User;
import cn.bqjr.platform.model.res.TestRes;
import cn.bqjr.platform.read.service.ReadTestService;
import cn.bqjr.platform.write.service.WriteTestService;



@Controller
@RequestMapping("/test")
public class TestController {
    @Autowired
    private WriteTestService writeTestService;
    @Autowired
    private ReadTestService readTestService;

    @RequestMapping(value = "/user/select",method = RequestMethod.POST)
    @ResponseBody
    public TestRes user(@RequestBody User user){
    	TestRes res = new TestRes();
    	List<User> list = readTestService.selectUser(user);
    	res.setList(list);
        return res;
    }
    
    @ResponseBody
    @RequestMapping(value = "/order",method = RequestMethod.POST)
	public TestRes order(@RequestBody Order order){
    	TestRes res = new TestRes();
    	int successSize = writeTestService.createOrder(order);
    	res.setSuccessSize(successSize);
    	return res;
    }
    
    @RequestMapping(value="/selectUser/{contrNbr}/{dcn}", method = RequestMethod.POST)
    @ResponseBody
    public String selectUser(@PathVariable String contrNbr,@PathVariable String dcn){
    	String dbKey = dcn;    	
    	String res = readTestService.selectJudgeContrIsOverdueByContrNbr(dbKey,contrNbr);
    	
        return res+"&dcn="+dcn;
    }

}
